Learn R Programming

VeryLargeIntegers (version 0.1.8)

12. Perfect power: Perfect Power Tools for vli Objects

Description

A positive integer is a perfect power if it can be expressed as an integer power of another positive integer. That is, a positive integer x is a perfect power if there exist two positive integers a and b such that x = a^b (note that a and b might not be unique).

Usage

perfectpow(x)

# S3 method for default perfectpow(x)

# S3 method for numeric perfectpow(x)

# S3 method for vli perfectpow(x)

is.perfectpow(x)

# S3 method for default is.perfectpow(x)

# S3 method for numeric is.perfectpow(x)

# S3 method for vli is.perfectpow(x)

Value

is.perfectpow(x) returns a Boolean

perfectpow(x) returns a list of two objects of class vli

Arguments

x

object of class vli or 32 bits integer

Author

Javier Leiva Cuadrado

Details

The function is.perfectpow(x) returns TRUE if there exist two positive integers a and b such that x = a^b, and returns FALSE if there not exist.

The function perfectpow(x) returns a list of two vli objects, a and b, such that x = a^b. If there not exist such numbers, the two vli objects will be equal to zero. Although the concept is usually defined only for positive integers, the function has been also programmed to work with negative integers.

Examples

Run this code
x <- as.vli("234925792")
is.perfectpow(x)

x <- as.vli("77808066022325383192121677734375")
is.perfectpow(x)
res <- perfectpow(x)
res
res[[1]]^res[[2]]

Run the code above in your browser using DataLab